﻿using MiniFox.Infrastructure;
using Newtonsoft.Json;

namespace Sys.Core.Models.VO
{
    [JsonObject]
    public class ModuleActionVo
    {
        [JsonProperty("actionId")]
        public string ActionID { get; set; }

        [JsonProperty("actionName")]
        public string ActionName { get; set; }

        [JsonProperty("uri")]
        public string Uri { get; set; }

        [JsonIgnore]
        public string ApplicationDomain { get; set; }

        [JsonIgnore]
        public string ApplicationPath { get; set; }

        [JsonIgnore]
        public bool RequireSSL { get; set; }

        [JsonIgnore]
        public string PortNumber { get; set; }

        [JsonIgnore]
        public string FullHost
        {
            get
            {
                if (!string.IsNullOrEmpty(this.ApplicationDomain))
                {
                    string host = this.ApplicationDomain.Replace("/", "");
                    string protocal = this.RequireSSL ? "https:" : "http:";
                    string port = (string.IsNullOrEmpty(this.PortNumber) || this.PortNumber.Trim() == "80") ? string.Empty : (":" + PortNumber);
                    return (protocal + "//" + host + port);

                }
                else
                {
                    return string.Empty;
                }
            }
        }

        [JsonProperty("fullPath")]
        public string FullPath
        {
            get
            {
                if (string.IsNullOrEmpty(this.ApplicationPath) || this.ApplicationPath.Trim() == "/" || this.ApplicationPath.Trim() == "~/")
                    return FullHost;
                string appPath = this.ApplicationPath.Trim('/');
                return FullHost + "/" + appPath;
            }
        }

        [JsonProperty("fullUri")]
        public string FullUri
        {
            get
            {
                string fullUri;
                if (string.IsNullOrWhiteSpace(this.Uri) || this.Uri.Trim() == "/" || this.Uri.Trim() == "~/")
                {
                    fullUri = this.FullPath;
                }
                else
                {
                    string uri = this.Uri.Trim('/');
                    if (this.Uri.StartsWith("http://") || this.Uri.StartsWith("https://") || this.Uri.StartsWith("ftp://") || this.Uri.StartsWith("ftps://"))
                        fullUri = uri;
                    else
                        fullUri = this.FullPath + "/" + uri;
                }

                return fullUri;
            }
        }

        [JsonProperty("createTime")]
        public DateTime CreateTime { get; set; }

        [JsonProperty("updateTime")]
        public DateTime UpdateTime { get; set; }
    }
}
